package work20250104;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author zdl
 * @date 2025/1/4
 */
public class Demo4 {
    public static void main(String[] args) {
        //4、格式化当前日期并打印，然后输出当前日期是今年的第几天？
        //使用jdk8 新特性
        test1();

        //原始Date版本
        test2();
    }
    public static void test1(){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDate = now.format(dtf);
        System.out.println("当前日期: " + formattedDate);
        int dayOfYear = now.getDayOfYear();
        System.out.println("今天是今年的第 " + dayOfYear + " 天");
    }
    public static void test2(){
        Date date = new Date();
        SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = sdf.format(date);
        System.out.println("当前时间:"+s);
        int i;
        String s1 = s.substring(8, 10);
        switch (date.getMonth()+1){
            case 1:
                System.out.println("当前日期是今年的第:"+s1+"天");
                break;
            case 2:
                i = Integer.parseInt(s1) + 31;
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 3:
                i = Integer.parseInt(s1) + (31+ 28);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 4:
                i = Integer.parseInt(s1) + (31+ 28+ 31);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 5:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 6:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30+ 31);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 7:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30+ 31+ 30);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 8:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30+ 31+ 30 +31);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 9:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30+ 31+ 30 +31+30);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 10:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30+ 31+ 30 +31+30+ 31);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 11:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30+ 31+ 30 +31+30+ 31+31);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
            case 12:
                i = Integer.parseInt(s1) + (31+ 28+ 31+30+ 31+ 30 +31+30+ 31+31+30);
                System.out.println("当前日期是今年的第:"+i+"天");
                break;
        }
    }
}
